package com.baidu.health.utils;

import com.baidu.health.mapper.TbFeedbackMapper;
import com.baidu.health.pojo.TbFeedback;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;

@Component
public class MqFilter {

    @Autowired
    TbFeedbackMapper feedbackMapper;

    @RabbitListener(queues = "userFeedback",concurrency = "1")
    public void checkFeedback(@RequestBody TbFeedback feedback, Message message, Channel channel)throws Exception{
        System.out.println(feedback);
        feedback.setUpdateTime(new Date());
        feedbackMapper.updateById(feedback);

        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        channel.basicAck(deliveryTag,false);
        channel.basicNack(deliveryTag,false,false);
    }

}
